package com.edu.bhu.admin.controller.admin;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.edu.bhu.common.annotation.Log;
import com.edu.bhu.common.enums.BusinessType;
import com.edu.bhu.admin.domain.HouTag;
import com.edu.bhu.admin.service.IHouTagService;
import com.edu.bhu.common.core.controller.BaseController;
import com.edu.bhu.common.core.domain.AjaxResult;
import com.edu.bhu.common.utils.poi.ExcelUtil;
import com.edu.bhu.common.core.page.TableDataInfo;

/**
 * 房屋标签Controller
 * 
 * @author zhangkeyi
 * @date 2022-02-22
 */
@Controller
@RequestMapping("/admin/tag")
public class HouTagController extends BaseController
{
    private String prefix = "admin/tag";

    @Autowired
    private IHouTagService houTagService;

    @RequiresPermissions("admin:tag:view")
    @GetMapping()
    public String tag()
    {
        return prefix + "/tag";
    }

    /**
     * 查询房屋标签列表
     */
    @RequiresPermissions("admin:tag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HouTag houTag)
    {
        startPage();
        List<HouTag> list = houTagService.selectHouTagList(houTag);
        return getDataTable(list);
    }

    /**
     * 根据房屋id查询房屋标签列表(不分页)
     */
    @RequiresPermissions("admin:tag:list")
    @PostMapping("/listByHouseIdNoPage/{houseId}")
    @ResponseBody
    public List<HouTag> listByHouseIdNoPage(@PathVariable("houseId") Long houseId)
    {
        List<HouTag> list = houTagService.selectAuthHouTagByHouseId(houseId);
        return list;
    }

    /**
     * 导出房屋标签列表
     */
    @RequiresPermissions("admin:tag:export")
    @Log(title = "房屋标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HouTag houTag)
    {
        List<HouTag> list = houTagService.selectHouTagList(houTag);
        ExcelUtil<HouTag> util = new ExcelUtil<HouTag>(HouTag.class);
        return util.exportExcel(list, "房屋标签数据");
    }

    /**
     * 新增房屋标签
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存房屋标签
     */
    @RequiresPermissions("admin:tag:add")
    @Log(title = "房屋标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HouTag houTag)
    {
        return toAjax(houTagService.insertHouTag(houTag));
    }

    /**
     * 修改房屋标签
     */
    @RequiresPermissions("admin:tag:edit")
    @GetMapping("/edit/{tagId}")
    public String edit(@PathVariable("tagId") Long tagId, ModelMap mmap)
    {
        HouTag houTag = houTagService.selectHouTagByTagId(tagId);
        mmap.put("houTag", houTag);
        return prefix + "/edit";
    }

    /**
     * 修改保存房屋标签
     */
    @RequiresPermissions("admin:tag:edit")
    @Log(title = "房屋标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HouTag houTag)
    {
        return toAjax(houTagService.updateHouTag(houTag));
    }

    /**
     * 删除房屋标签
     */
    @RequiresPermissions("admin:tag:remove")
    @Log(title = "房屋标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(houTagService.deleteHouTagByTagIds(ids));
    }
}
